/*
 *  Copyright (C) void Team 2010 Pedro Batista
 * 
 *  http://code.google.com/p/capacitec
 * 
 *  This file is part of capacitec.
 * *  capacitec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  capacitec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with capacitec.  If not, see <http://www.gnu.org/licenses/>.
 */
package controller;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import dao.ProgramaDao;
import entidades.Programa;
import seguranca.anotacoes.RestritoCoordenador;

/**
 *
 * @author pedro
 */
@Resource
public class ProgramaController {

	private final ProgramaDao programdaDao;
	private final Result resul;

	/**
	 *
	 * @param programdaDao
	 * @param resul
	 */
	public ProgramaController(ProgramaDao programdaDao, Result resul) {
		this.programdaDao = programdaDao;
		this.resul = resul;
	}

	/**
	 * Fornece o formulário para cadastro de programa.
	 */
	@Get
	@Path("/programa/novo")
	@RestritoCoordenador
	public void formulario() {
		//TODO: Tratar inserção de programa duplicado (JavaScript)
		//TODO: Adicionar validação de campos.
	}

	/**
	 * Adiciona um novo programa ao banco de dados.
	 * @param programa Programa a ser adicionado.
	 */
	@Post
	@Path("/programa")
	@RestritoCoordenador
	public void adiciona(Programa programa) {
		programdaDao.salva(programa);
		//TODO: fazer com que redirecione para o subprograma com o ultimo programa cadastrado selecionado.
		resul.redirectTo(SubProgramaController.class).formulario();
	}
}
